<?php

namespace App\Utils;

use App\Models\Region;

final class RegionUtil
{
    private static $regionFullName = [];
    private static $regionFullCode = [];

    public static function getFullName(Region $region)
    {
        if (is_null($region)) return [];

        if ($region->parent()->exists()) {
            /** @var Region $parent */
            $parent = $region->parent()->first();
            self::getFullName($parent);
        }

        array_push(self::$regionFullName, $region->name);

        return self::$regionFullName;
    }

    public static function getFullCode(Region $region = NULL)
    {
        if (is_null($region)) return [];

        if ($region->parent()->exists()) {
            /** @var Region $parent */
            $parent = $region->parent()->first();
            self::getFullCode($parent);
        }

        array_push(self::$regionFullCode, $region->code);

        return self::$regionFullCode;
    }
}
